package main;
public class PowerStation
{
	private boolean	isChargeable, isCharged, isCharging, isExtended, isExtending;
	private boolean	door;
	Vehicle vehicle;

	public PowerStation()
	{
		isCharged = false;
		isCharging = false;
		isChargeable = true;
		isExtended = false;
		isExtending = false;
		door = false;
		vehicle = null;
		
	}
	public void setVehicle(Vehicle v)
	{
		//When BT connects create car
		vehicle = v;
	}
	public boolean getIsCharging()
	{
		return isCharging;
	}

	public boolean getIsCharged()
	{
		return isCharged;
	}

	public boolean getIsExtended()
	{
		return isExtended;
	}

	public boolean getIsExtending()
	{
		return isExtending;
	}

	public boolean getDoor()
	{
		return door;
	}

	private void setIsCharging(boolean charge)
	{
		if (door && isExtended)
			isCharging = charge;
	}

	private void setIsCharged()
	{
	}

	private void setDoor(boolean status)
	{
		door = status;
	}

	private void setIsExtended(boolean status)
	{
		isExtended = status;
	}

	private void openDoor()
	{
		// Send signal to open box door.
		// wait for signal that door is open.
		setDoor(true);
		System.out.println("Door Opened");
	}

	private void closeDoor()
	{
		if (!isExtended && !isExtending)
		{
			// Send signal to close box door.
			// wait for signal that door is closed.
			setDoor(false);
			System.out.println("Door Closed");
		}
		else
			System.out.println("Arm is extending/extended door will not close.");
	}

	public void extendArm()
	{
		while (!door)
			openDoor();
		while (!isExtended)
		{
			// send signal to extend arm.
			// wait for signal that arm is extended.
			setIsExtended(true);
		}
		System.out.println("Arm Extended.");
	}

	public void retractArm()
	{
		while (isExtended || isExtending)
		{
			// send signal to retract arm.
			// wait for signal that arm is retracted.
			setIsExtended(false);
		}
		while (door)
			closeDoor();
		System.out.println("Arm is Retracted.");
	}

	public void startCharging()
	{
		if (!door)
			System.out.println("Cant start charging.  The door is not open.");
		else
			if (isExtending)
				System.out.println("Cant start charging.  Arm is still extending.");
			else
				if (isCharged)
					System.out.println("Cant start charging.  Battery is already charged.");
				else
					if (isCharging)
						System.out.println("Cant start charging.  Battery is already charging.");
					else
						if (!isExtended)
							System.out.println("Cant start charging.  Arm is not extended.");
						else
							System.out.println("Battery is Charging.");
		Thread checkCharge = new Thread(new Runnable() {
			public void run()
			{
				while(true)
				{
					
				}
			}
		});
		checkCharge.start();
	}
}
